package com.zheng.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zheng.common.Result;
import com.zheng.entity.User;
import com.zheng.entity.UserShop;
import com.zheng.service.UserShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/userShop")
public class UserShopController {

    @Autowired
    private UserShopService userShopService;

    @GetMapping
    //第一个参数当前页，当个参数每页个数，第三个参数模糊查询的条件
    public Result<?> selectAll(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestParam String search, @RequestParam String option){


        //对user进行分页 page分页需要两个参数pageNum, pageSize
        Page<UserShop> page = new Page<>(pageNum, pageSize);
        //创建QueryWrapper进行过条件查询分页
        QueryWrapper<UserShop> queryWrapper =new QueryWrapper<>();
        //如果字段的值不为空进行模糊查询  空！=null
        //用到了hutool工具类StrUtil 可以去官网进行查看hutool.cn
        if(StrUtil.isNotBlank(search)){
            queryWrapper.like(option,search);
        }
        Page<UserShop> userPage = userShopService.page(page,queryWrapper);
        return Result.success(userPage);
    }

}
